﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Ebada.Platform.Model;
using Ebada.UI.Base;
using Ebada.Client;
using Ebada.Core;
using Ebada.Client.Platform;
using System.Collections;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace Ebada.Modules.Vehicle
{
    /// <summary>
    /// 车辆备品登记编辑
    /// </summary>
    public partial class frmVehiclePartsEdit : FormBase, IPopupFormEdit {
        SortableSearchableBindingList<mOrg> m_OrgID = new SortableSearchableBindingList<mOrg>();
        SortableSearchableBindingList<Empolyees> m_Employ= new SortableSearchableBindingList<Empolyees>();

        public frmVehiclePartsEdit()
        {
            InitializeComponent();
        }
        private void frmVehiclePartsEdit_Load(object sender, EventArgs e)
        {

            Add_FromDIC();

        }
        
        Vehicle_Common vc = new Vehicle_Common();

        private void Add_FromDIC()
        {
            vc.Add_DIC("VehiclePartType", cobVehiclePartType);
         
        }
        void dataBind() 
        {

            this.txtVehiclePartID.DataBindings.Add("EditValue", rowData, "VehiclePartID");
            this.cobVehiclePartType.DataBindings.Add("EditValue", rowData, "VehiclePartType");
            this.luVehicleID.DataBindings.Add("EditValue", rowData, "VehicleID");
            this.luEmployeeID.DataBindings.Add("EditValue", rowData, "EmployeeID");
            this.txtVehiclePartNum.DataBindings.Add("EditValue", rowData, "VehiclePartNum");
            this.txtVehiclePartName.DataBindings.Add("EditValue", rowData, "VehiclePartName");
            this.txtVehiclePartPrice.DataBindings.Add("EditValue", rowData, "VehiclePartPrice");
            this.meRemark.DataBindings.Add("EditValue", rowData, "Remark");
           
        }
       
        #region IPopupFormEdit Members
        private VehicleParts rowData = null;

        public object RowData {
            get {
                return rowData;
            }
            set {
                if (value == null) return;
                if (rowData == null) {
                    this.rowData = value as VehicleParts;
                    dataBind();
                    InitComboBoxData();
                } else {
                    ConvertHelper.CopyTo<VehicleParts>(value as VehicleParts, rowData);
                }
            }
        }

        #endregion

        private void InitComboBoxData() 
        {
           IList<Empolyees> empl_list = MainHelper.PlatformSqlMap.GetList<Empolyees>("");
           this.SetComboBoxData(this.luEmployeeID, "Empolyee_Name", "Empolyee_ID", "请选择", "人员名称", empl_list);
           IList<Vehicles> vehi_list = MainHelper.PlatformSqlMap.GetList<Vehicles>("");
           this.SetComboBoxData2(this.luVehicleID, "VehicleNumber", "VehicleID", "请选择", "车牌号码", vehi_list);

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="comboBox"></param>
        /// <param name="displayMember"></param>
        /// <param name="valueMember"></param>
        /// <param name="nullTest"></param>
        /// <param name="cnStr"></param>
        /// <param name="post"></param>
       //人员选择器
        public void SetComboBoxData(DevExpress.XtraEditors.LookUpEdit comboBox, string displayMember, string valueMember, string nullTest, string cnStr, IList<Empolyees> post)
        {
            comboBox.Properties.Columns.Clear();
            comboBox.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            comboBox.Properties.DataSource = post;
            comboBox.Properties.DisplayMember = displayMember;
            comboBox.Properties.ValueMember = valueMember;
            comboBox.Properties.NullText = nullTest;
            comboBox.Properties.Columns.AddRange(new DevExpress.XtraEditors.Controls.LookUpColumnInfo[] {
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo(valueMember, "ID", 20, DevExpress.Utils.FormatType.None, "", false, DevExpress.Utils.HorzAlignment.Default),
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo(displayMember, cnStr)});
        }
        //车牌号选择器
        public void SetComboBoxData2(DevExpress.XtraEditors.LookUpEdit comboBox, string displayMember, string valueMember, string nullTest, string cnStr, IList<Vehicles> post)
        {
            comboBox.Properties.Columns.Clear();
            comboBox.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            comboBox.Properties.DataSource = post;
            comboBox.Properties.DisplayMember = displayMember;
            comboBox.Properties.ValueMember = valueMember;
            comboBox.Properties.NullText = nullTest;
            comboBox.Properties.Columns.AddRange(new DevExpress.XtraEditors.Controls.LookUpColumnInfo[] {
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo(valueMember, "ID", 20, DevExpress.Utils.FormatType.None, "", false, DevExpress.Utils.HorzAlignment.Default),
            new DevExpress.XtraEditors.Controls.LookUpColumnInfo(displayMember, cnStr)});
        }
        
      

        private void btnOK_Click(object sender, EventArgs e)
        {
          
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
       
        //选择领用人
        private void luEmployeeID_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (e.Button.Index == 1)
            {
                Ebada.Client.Platform.Selector.frmEmpSelectorByOrgInfo frm = new Ebada.Client.Platform.Selector.frmEmpSelectorByOrgInfo();
                frm.InitionData("", false, false);
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    luEmployeeID.EditValue = frm.CurrentEmp.Empolyee_ID;
                    rowData.EmployeeName = frm.CurrentEmp.Empolyee_Name;
                }
            }
        }
        private void luEmployeeID_EditValueChanged(object sender, EventArgs e)
        {
            rowData.EmployeeName = luEmployeeID.Text;
        }
        //车牌号选择
        private void luVehicleID_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (e.Button.Index == 1)
            {

                frmVehiclesSeletcter frm = new frmVehiclesSeletcter();
                frm.InitData_Slect("");
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    luVehicleID.EditValue = frm.SelectObj.VehicleID;
                }
            }

        }

      
      

      
    }
}